package com.pokerbean.housingremind.service.impl;

import com.pokerbean.housingremind.service.CatchService;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * created by IntelliJ IDEA
 *
 * @author: pokerbean
 * @e-mail: brutalmraz@gmail.com
 * @time: 2018/5/5 23:42
 * @desc: CatchServiceImpl
 */
@Slf4j
@Component
public class CatchServiceImpl implements CatchService {

    @Override
    public Document getDocument(String url) {
        try {
            Document document = Jsoup.connect(url).get();
            log.info("正在爬取房协网 ：{}",document);
            return document;
        } catch (IOException e) {
            log.error("system error :{}",e.getMessage());
        }
        return null;
    }

    public static void main(String[] args) {
        CatchServiceImpl t = new CatchServiceImpl();
        Document doc = t.getDocument("https://www.cdfangxie.com/Infor/type/typeid/36.html");
        Elements elements = doc.select("[class=sp_name]");
//        System.out.println(elements);
        for (Element element : elements) {
            System.out.println("楼盘名称："+element.text());
            Element element1 = element.nextElementSibling();
            System.out.println("拿证时间："+element1.text());
        }

    }
}
